﻿using System;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BHB.Library.Navigation
{
    public class DialogUriMapping:CustomUriMapping
    {
        public string UnmappedUri { get; set; }
        public Type DialogType { get; set; }
        public Action<ChildWindow> PostCreationAction { get; set; }
        
        public override bool MapUri(Uri unmappedUri, out Uri mappedUri)
        {
            mappedUri = null;
            if (DialogType!=null && !string.IsNullOrEmpty(UnmappedUri) && unmappedUri.ToString()==UnmappedUri)
            {
                ChildWindow childWindow = Activator.CreateInstance(DialogType) as ChildWindow;

                if (PostCreationAction != null)
                {
                    PostCreationAction(childWindow);
                }

                if (childWindow != null)
                {
                    childWindow.Show();
                    return true;
                }
            }
            return false;
        }
    }
}
